<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	set_html('title','酒店评论');
	exi($return);
}
if($_RQ['op']=='commentorder'){
			$id=intval($_RQ['id']);
			if(!$id){
				exi('订单不存在，请重新选择订单','error');
			}
			$item=pdo_get('jy_jd_order',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id)); 
			$item['room']=pdo_get('jy_jd_room',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['roomid']));
			$item['room']['image']=tomedia($item['room']['image']);
			$item['hotel']=pdo_get('jy_jd_hotel',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['hotelid']),array('id','title','image'));
			$comment=$this->pdo_get('comments',array('orderid'=>$id,'goodsid'=>$item['roomid'],'commentid'=>0));		
			if($comment){
				$comment['images']=$comment['images']?json_decode($comment['images'],true):array();
				$post=$comment;
				if($comment['createtime']){
					$comment_changedays=1;
					$endpingjiatime = $comment['createtime'] + $comment_changedays*24*3600;
					if($endpingjiatime>TIMESTAMP){
						$item['pingjia']=1;//1修改评价；2追加评价
					}else{
						$zuipingjia = pdo_count('jy_jd_comments',array('uniacid'=>$_SESSION['uniacid'],'orderid'=>$id,'goodsid'=>$item['roomid'],'commentid >'=>0),'id');
						if($zuipingjia<1){
							$item['pingjia']=2;
						}else{
							$item['pingjia']=3;
						}
					}
				}
				if($comment['show']==1 && $item['pingjia']!=1){
					unset($order_goods[$k]);
				}
			}else{
				$post=array(
					'orderid'=>$id,
					'hotelid'=>$item['hotelid'],
					'goodsid'=>$item['roomid'],
					'star'=>5,
					'sendstar'=>0,
					'fuwustar'=>0,
					'images'=>array(),
				);
			}
			$return['post']=$post;
			$return['item']=$item;
			exi($return);
}

if($_RQ['op']=='submit'){
	$postdata=get_postdata();
	$data=array(
		'content'=>$postdata['content'],
		'images'=>ijson_encode($postdata['images']),
		'star'=>intval($postdata['star']),
		'fuwustar'=>intval($postdata['fuwustar']),
	);
	$comment_id=$this->pdo_getcolumn('comments',array('orderid'=>intval($postdata['orderid']),'goodsid'=>intval($postdata['goodsid'])),'id');
	if($comment_id){
		if($postdata['show']==1){
			exi('该评价已生效显示，不可修改！','error','goback');
		}
		$this->pdo_update('comments',$data,array('id'=>$comment_id));
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'show'=>0,
			'hotelid'=>intval($postdata['hotelid']),
			'goodsid'=>intval($postdata['goodsid']),
			'orderid'=>intval($postdata['orderid']),
			'createtime'=>TIMESTAMP,
		);
		$data=array_merge($insert,$data);
		$this->pdo_insert('comments',$data);
		$this->update('order',array('iscomment'=>1),array('id'=>$insert['orderid'],'uniacid'=>$_SESSION['uniacid']));
	}
	exi('评价成功！','','/order/');
}
?>